#include <deque>
#include <queue>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#define x first
#define y second
#define foo(i, j, k) for (i = 0; i < j; i += k)
#define fol(i, j, k) for (i = 1; i <= j; i += k)
using namespace std;
typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, char> PIC;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e6 + 10;
LL sum[N];
LL n;
int ans[N], L;

void init() {
    sum[1] = 1;
    for (int i = 2; i < N; i ++) {
        sum[i] = sum[i - 1] + i * i;
    }
}

bool is(LL xi, int k) {

    for (int i = k; i >= 1; i --) {
//        cout << xi << ' ' << i << endl;
        if (xi >= 0) {
            ans[++ L] = 1;
            xi -= (LL) i * i;
        }
        else {
            ans[++ L] = 0;
            xi += (LL) i * i;
        }
    }
    if (xi == 0) return true;
    else return false;
}

int main () {

    int T;
    scanf("%d", &T);
    init();
    while (T --) {
        scanf("%lld", &n);
        for (int i = 1; i <= n + 2; i ++) {
            LL maxv = sum[i], minv = sum[i - 1] + i * i;
            minv = -minv;
//            cout << i << ' ' << maxv << ' ' << minv << endl;
            if (minv <= n && n <= maxv) {
                L = 0;
                if (is(n, i)) {
                    printf("%d\n", i);
                    for (int j = L; j >= 1; j --) {
                        printf("%d", ans[j]);
                    }
                    puts("");
                    break;
                }
            }
            if (minv > n) break;
        }

    }

    return 0;
}